package com.gec.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gec.entity.Good;
import com.gec.entity.GoodType;
import com.gec.entity.Shop;
import com.gec.service.GoodService;
import com.gec.service.GoodTypeService;
import com.gec.service.ShopService;
import com.gec.service.impl.GoodServiceImpl;
import com.gec.service.impl.GoodTypeServiceImpl;
import com.gec.service.impl.ShopServiceImpl;

@WebServlet("/cheock")
public class CheockFoodServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 获取商店id(shopid)
		Integer shopid = Integer.parseInt(req.getParameter("id"));
		ShopService shopService = new ShopServiceImpl();
		Shop shop = shopService.findShopId(shopid);
		req.setAttribute("shop", shop);

		// 左边分类
		GoodTypeService gtservice = new GoodTypeServiceImpl();
		List<GoodType> gtlist = null;
		gtlist = gtservice.findById(shopid);
		req.setAttribute("gtlist", gtlist);

		// 获取商品id(goodid)
		GoodService service = new GoodServiceImpl();
		List<Good> good = null;
		int typeid = 0;
		if(req.getParameter("typeid") != null)
			typeid = Integer.parseInt(req.getParameter("typeid"));
		if (typeid == 0)
			good = service.findHots(shopid);
		else
			good = service.findListByType(typeid);
		req.setAttribute("good", good);
		req.getRequestDispatcher("/WEB-INF/jsp/cheockfood.jsp").forward(req, resp);
	}
}
